#include <bits/stdc++.h>
using namespace std;
bool ok[3010][3010];
int d[3010],v[3010],a[3010],p[3010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin >> t;
    int ans = 0;
    while(t--){
        for(int i = 1;i <= 3000;i++){
            for(int j = 1;j <= 3000;j++){
                ok[i][j] = false;
            }
        }
        int n,m,l,V;
        cin >> n >> m >> l >> V;
        for(int i = 1;i <= n;i++){
            cin >> d[i] >> v[i] >> a[i];
        }
        for(int i = 1;i <= m;i++){
            cin >> p[i];
        }
        for(int i = 1;i <= n;i++){
            //cout << V << " " << v[i] << endl;
            bool kf = false;
            for(int j = 1;j <= m;j++){
                if(p[j] >= d[i] && V > v[i]){
                    ok[i][j] = true;
                    kf = true;
                    //cout << 't' << endl;
                }
            }
            if(kf) ans++;
        }
        cout << ans << endl;
        int gb = 0;
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= m;j++){
                if(ok[i][j]){
                    bool kf = true;
                    for(int k = 1;k <= n;k++){
                            bool nn = false;
                        for(int l = 1;l <= m;l++){
                            if(l != j && ok[k][l]){
                                nn = true;
                                break;
                            }
                        }
                        if(!nn){
                            kf = false;
                            break;
                        }
                    }
                    if(kf){
                        gb++;
                        for(int k = 1;k <= n;k++) ok[n][j] = false;
                    }
                }
            }
        }
        cout << gb << endl;
    }
    return 0;
}
